package Sort;

import java.util.Arrays;
import java.util.Comparator;

public class _179_LargestNumber {
    private class StringComparator implements Comparator<String> {

        @Override
        public int compare(String o1, String o2) {
            String a = o1 + o2;
            String b = o2 + o1;
            return b.compareTo(a);
        }
    }

    public String largestNumber(int[] nums) {
        String[] ans = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            ans[i] = String.valueOf(nums[i]);
        }
        Arrays.sort(ans, new StringComparator());

        if (ans[0].equals("0")) {
            return "0";
        }
        StringBuffer sb = new StringBuffer();
        for (String s : ans) {
            sb.append(s);
        }
        return sb.toString();
    }
}
